<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    // var p = new Promise(function (resolve, reject) {
    //     reject(1);
    // })
    // console.log(p); // {<fulfilled:1>}

    // Promise.myReject = function (arg) {
    //     var p = new Promise(function (resolve, reject) {
    //         reject(arg);
    //     })
    //     return p;   // {<rejected:arg>}
    // }




    // Promise.reject()
    // 1. 可以根据传入的参数,快速得到 已失败 状态的Promise对象 (参数会作为Promise对象的数据存储)

    // var p = Promise.reject(1);
    // console.log(p);   // {<rejected:1>}

    // var p1 = Promise.reject(p);
    // console.log(p1);  // {<rejected:p>}






    var p1 = getNumAsync(1, 2000);
    var p2 = getNumAsync(2, 1000);
    var p3 = getNumAsync(3, 3000);

    // var p = Promise.myAll([p1, p2, p3]);
    var p = Promise.all([p1, p2, p3, 4, 5, 6]);

    p.then(list => {
        console.log("fulfilled", list);
    }).catch(err => {
        console.log("rejected", err);
    })


    function getNumAsync(num, delay = 0, isFulfilled = true) {
        var p = new Promise(function (resolve, reject) {
            setTimeout(function () {
                isFulfilled ? resolve(num) : reject(num);
            }, delay);
        });
        return p;
    }





</script>

</html>